/****** Object:  Table [dbo].[Widget]    Script Date: 04/25/2009 11:24:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Widget](
	[WidgetId] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](255) NOT NULL,
	[Url] [nvarchar](255) NOT NULL,
	[Description] [nvarchar](255) NOT NULL,
	[CreatedDate] [datetime] NOT NULL,
	[VersionNo] [tinyint] NOT NULL,
	[IsDefault] [bit] NOT NULL,
	[DefaultState] [nvarchar](max) NOT NULL,
	[Icon] [nvarchar](255) NOT NULL,
	[OrderNo] [tinyint] NOT NULL,
	[Active] [bit] NOT NULL,
	[LastUpdatedBy] [nvarchar] (50) NOT NULL,
	[LastUpdate] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[WidgetId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[Activity]    Script Date: 04/25/2009 11:24:54 ******/
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Activity](
	[ActivityId] [int] IDENTITY(1,1) NOT NULL,
	[Name] [varchar](50) NOT NULL,
	[Description] [varchar](255) NULL,
	[LastUpdate] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[ActivityId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO

/****** Object:  Table [dbo].[PortalUsers]    Script Date: 04/25/2009 11:24:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[PortalUsers](
	[ApplicationID] [int] NULL,
	[UserId] [int] IDENTITY(1,1) NOT NULL,
	[UserName] [varchar](255) NOT NULL,
	[UserAlias] [varchar](50) NOT NULL,
	[LastActivityDate] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[UserId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO

/****** Object:  Table [dbo].[AuditTrail]    Script Date: 04/25/2009 11:24:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[AuditTrail](
	[AuditTrailId] [int] IDENTITY(1,1) NOT NULL,
	[UserId] [int] NOT NULL,
	[ActivityId] [int] NOT NULL,
	[ActivityStartTime] [datetime] NOT NULL,
	[ActivityEndTime] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[AuditTrailId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[WidgetInstance]    Script Date: 04/25/2009 11:24:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[WidgetInstance](
	[WidgetInstanceId] [int] IDENTITY(1,1) NOT NULL,
	[WidgetId] [int] NOT NULL,
	[UserId] [int] NOT NULL,
	[ColumnNo] [smallint] NOT NULL,
	[OrderNo] [smallint] NOT NULL,
	[Expanded] [tinyint] NOT NULL,
	[Title] [nvarchar](255) NOT NULL,
	[State] [nvarchar](max) NOT NULL,
	[CreatedDate] [datetime] NOT NULL,
	[LastUpdate] [datetime] NOT NULL,
	[VersionNo] [tinyint] NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[WidgetInstanceId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

/****** Object:  Default [DF__Widget__IsDefaul__173876EA]    Script Date: 04/25/2009 11:24:55 ******/
ALTER TABLE [dbo].[Widget] ADD  DEFAULT ((0)) FOR [IsDefault]
GO
ALTER TABLE [dbo].[Widget] ADD  CONSTRAINT [DF_Widget_Active]  DEFAULT ((1)) FOR [Active]
GO
/****** Object:  ForeignKey [FK__AuditTrai__Activ__1BFD2C07]    Script Date: 04/25/2009 11:24:54 ******/
ALTER TABLE [dbo].[AuditTrail]  WITH CHECK ADD FOREIGN KEY([ActivityId])
REFERENCES [dbo].[Activity] ([ActivityId])
GO
/****** Object:  ForeignKey [FK__AuditTrai__UserI__1CF15040]    Script Date: 04/25/2009 11:24:54 ******/
ALTER TABLE [dbo].[AuditTrail]  WITH CHECK ADD FOREIGN KEY([UserId])
REFERENCES [dbo].[PortalUsers] ([UserId])
GO
/****** Object:  ForeignKey [FK__WidgetIns__UserI__239E4DCF]    Script Date: 04/25/2009 11:24:55 ******/
ALTER TABLE [dbo].[WidgetInstance]  WITH CHECK ADD FOREIGN KEY([UserId])
REFERENCES [dbo].[PortalUsers] ([UserId])
GO
/****** Object:  ForeignKey [FK__WidgetIns__UserI__29572725]    Script Date: 04/25/2009 11:24:55 ******/
ALTER TABLE [dbo].[WidgetInstance]  WITH CHECK ADD FOREIGN KEY([UserId])
REFERENCES [dbo].[PortalUsers] ([UserId])
GO
/****** Object:  ForeignKey [FK__WidgetIns__Widge__22AA2996]    Script Date: 04/25/2009 11:24:55 ******/
ALTER TABLE [dbo].[WidgetInstance]  WITH CHECK ADD FOREIGN KEY([WidgetId])
REFERENCES [dbo].[Widget] ([WidgetId])
GO
/****** Object:  ForeignKey [FK__WidgetIns__Widge__2A4B4B5E]    Script Date: 04/25/2009 11:24:55 ******/
ALTER TABLE [dbo].[WidgetInstance]  WITH CHECK ADD FOREIGN KEY([WidgetId])
REFERENCES [dbo].[Widget] ([WidgetId])
GO
